﻿
Imports lock_t = lockWrapper(Of locks.eventCombLock)

Public Class locked_deliverer_wrapper
    Inherits deliverer_wrapper(Of async_deliverer_t)

    Private ReadOnly l As lock_t = Nothing

    Public Sub New(ByVal d As async_deliverer_t)
        MyBase.New(d)
        l = New lock_t()
    End Sub

    Public Overrides Function deliver(ByVal c As [case]) As eventComb
        Dim ec As eventComb = Nothing
        Return New eventComb(Function() As Boolean
                                 Return waitfor(l) AndAlso
                                        goto_next()
                             End Function,
                             Function() As Boolean
                                 ec = do_(Function() d.deliver(c), Nothing)
                                 Return waitfor(ec) AndAlso
                                        goto_next()
                             End Function,
                             Function() As Boolean
                                 l.release()
                                 Return ec.end_result() AndAlso
                                        goto_end()
                             End Function)
    End Function
End Class
